package  
{
	import net.flashpunk.graphics.TiledImage;
	import net.flashpunk.World;
	import net.flashpunk.FP;
	import net.flashpunk.utils.Input;
	import net.flashpunk.utils.Key;
	import net.flashpunk.graphics.Image;
	
	/**
	 * ...
	 * @author Donatello
	 */
	public class GameWorld extends World
	{
		protected var player:Player;
		protected var text:TextMessage;
		
		protected var inspectorCostum:Costum;
		protected var batmanCostum:Costum;
		
		protected var inspector:Boolean = false;
		protected var batman:Boolean = false;
		
		public var wallBreak:WallBreakable;
		
		private var back:Back;
		
		
		public function GameWorld() 
		{
			this.player = new Abed();
			
			back = new Back();
			
			add(back);
			
			this.add(player);
			
			//Agrego las paredes
			var i:int=0
			while ( i < FP.screen.width)
			{
				add(new Wall(i,0));
                add(new Wall(i,608));
				i += 32;	
			}
            i = 32;
			while (i < (FP.screen.height -32))
			{
				add(new Wall(0, i));
				if(i!=64 && i!=32 && i!=96)
					add(new Wall(768,i));
				
				i += 32;
			}
			
			i=0
			while ( i < 7) {
				add(new Wall(32+(32*i), 500));
				i++;
			}
			i=1
			while ( i < 5) {
				add(new Wall(768-(32*i), 500));
				i++;
			}
			
			add(new Wall(32, 220));
			add(new Wall(64, 220));
			add(new Wall(736, 100));
			
			wallBreak = new WallBreakable(768, 32);
			add(wallBreak);
			
			
			
			inspectorCostum = new Costum(50, 175, 0);
			batmanCostum = new Costum(700, 450, 1);
			
			add(inspectorCostum);
			add(batmanCostum);
			
		}
		
		override public function update():void
		{
			var px:Number = player.x;
			var py:Number = player.y;
			
			
			
			if (px > FP.screen.width)
			{	
				FP.world = new MainMenuWorld();
				removeAll();
			}
			if (player.collide("InspectorCostum", px, py))
			{
				inspector = true;
				remove(player)
				player = new Inspector(px,py);
				add(player);
				back.Change(2);
				remove(inspectorCostum);
			}
			
			if (player.collide("BatmanCostum", px, py))
			{
				batman = true;
				remove(player)
				player = new Batman(px,py);
				add(player);
				back.Change(1);
				remove(batmanCostum);
			}
			
			
			if (Input.check(Key.A))
			{	
				//Abed
				remove(player)
				player = new Abed(px,py);
				add(player);
				back.Change(0);
			}
			if (Input.check(Key.S))
			{	
				//Inspector
				if (inspector)
				{
					remove(player)
					player = new Inspector(px,py);
					add(player);
					back.Change(2);
				}
			}
			if (Input.check(Key.D))
			{	
				//Batman
				if(batman)
				{
					remove(player)
					player = new Batman(px,py);
					add(player);
					back.Change(1);
				}
			}
			
			
			player.actualizar();			
			super.update();
            
		}
		
	}

}